<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试依赖图功能</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        .test-button {
            background-color: #1890ff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin: 10px;
            font-size: 14px;
        }
        .test-button:hover {
            background-color: #40a9ff;
        }
        .result-container {
            margin-top: 20px;
            padding: 16px;
            border: 1px solid #d9d9d9;
            border-radius: 6px;
            background: #fafafa;
        }
        .json-display {
            background: #f5f5f5;
            padding: 16px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 12px;
            overflow: auto;
            max-height: 400px;
            white-space: pre-wrap;
            word-break: break-word;
        }
        .loading {
            text-align: center;
            padding: 20px;
            color: #666;
        }
        .error {
            color: #ff4d4f;
            background: #fff2f0;
            border: 1px solid #ffccc7;
            padding: 12px;
            border-radius: 4px;
        }
        .success {
            color: #52c41a;
            background: #f6ffed;
            border: 1px solid #b7eb8f;
            padding: 12px;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔗 模型依赖图功能测试</h1>
        <p>这个页面用于测试模型依赖图的API调用和数据显示功能。</p>

        <div style="background: #fff2f0; border: 1px solid #ffccc7; padding: 12px; border-radius: 4px; margin-bottom: 20px;">
            <h3 style="color: #ff4d4f; margin-top: 0;">🐛 调试信息</h3>
            <p><strong>问题发现</strong>: 点击"查看依赖图"按钮时，弹出框出现但没有发送网络请求！</p>
            <p><strong>预期行为</strong>: 点击按钮后应该立即发送API请求到 <code>/training_model_modelview/api/action/view_dependency_graph/{id}</code></p>
            <p><strong>调试步骤</strong>: 请打开浏览器控制台查看详细的调试日志</p>
        </div>
        
        <div>
            <h3>测试不同的模型ID:</h3>
            <button class="test-button" onclick="testDependencyGraph(1)">测试模型ID: 1</button>
            <button class="test-button" onclick="testDependencyGraph(2)">测试模型ID: 2</button>
            <button class="test-button" onclick="testDependencyGraph(3)">测试模型ID: 3</button>
            <button class="test-button" onclick="testDependencyGraph(999)">测试不存在的模型ID: 999</button>
        </div>
        
        <div>
            <h3>自定义测试:</h3>
            <input type="number" id="customModelId" placeholder="输入模型ID" style="padding: 8px; margin-right: 10px; border: 1px solid #d9d9d9; border-radius: 4px;">
            <button class="test-button" onclick="testCustomModelId()">测试自定义模型ID</button>
        </div>
        
        <div id="resultContainer" class="result-container" style="display: none;">
            <h3>API响应结果:</h3>
            <div id="resultContent"></div>
        </div>
    </div>

    <script>
        async function testDependencyGraph(modelId) {
            const resultContainer = document.getElementById('resultContainer');
            const resultContent = document.getElementById('resultContent');
            
            // 显示加载状态
            resultContainer.style.display = 'block';
            resultContent.innerHTML = '<div class="loading">🔄 正在加载依赖图数据...</div>';
            
            try {
                console.log('正在测试模型ID:', modelId);
                
                // 调用API
                const apiUrl = `/training_model_modelview/api/action/view_dependency_graph/${modelId}`;
                console.log('API请求URL:', apiUrl);
                
                const response = await fetch(apiUrl);
                const result = await response.json();
                
                console.log('API响应:', result);
                
                // 显示结果
                if (response.ok) {
                    resultContent.innerHTML = `
                        <div class="success">✅ API调用成功</div>
                        <div style="margin-top: 16px;">
                            <strong>响应状态:</strong> ${response.status} ${response.statusText}
                        </div>
                        <div style="margin-top: 16px;">
                            <strong>响应数据:</strong>
                            <div class="json-display">${JSON.stringify(result, null, 2)}</div>
                        </div>
                    `;
                } else {
                    resultContent.innerHTML = `
                        <div class="error">❌ API调用失败</div>
                        <div style="margin-top: 16px;">
                            <strong>响应状态:</strong> ${response.status} ${response.statusText}
                        </div>
                        <div style="margin-top: 16px;">
                            <strong>错误信息:</strong>
                            <div class="json-display">${JSON.stringify(result, null, 2)}</div>
                        </div>
                    `;
                }
            } catch (error) {
                console.error('请求失败:', error);
                resultContent.innerHTML = `
                    <div class="error">❌ 请求失败</div>
                    <div style="margin-top: 16px;">
                        <strong>错误详情:</strong> ${error.message}
                    </div>
                `;
            }
        }
        
        function testCustomModelId() {
            const customModelId = document.getElementById('customModelId').value;
            if (customModelId) {
                testDependencyGraph(parseInt(customModelId));
            } else {
                alert('请输入模型ID');
            }
        }
        
        // 页面加载完成后的提示
        window.onload = function() {
            console.log('依赖图测试页面已加载');
            console.log('您可以点击按钮测试不同的模型ID');
        };
    </script>
</body>
</html>
